from pd.struct import *
from pd.const import *
from pd.player.history import *
from pd.sim import *
from evo.cont import *
from fs.matlab import *

initial = [(C, C)]
tft = standardHistoryPlayer("tft", [(C, C)])
stft = standardHistoryPlayer("tft", [(D, D)])
stft.name = "stft"
allc = standardHistoryPlayer("allc", [])
alld = standardHistoryPlayer("alld", [])
pavlov = standardHistoryPlayer("pavlov", [(C, C)])
spavlov = standardHistoryPlayer("pavlov", [(C, D)])
spavlov.name = "spavlov"
rand = standardHistoryPlayer("rand", [])

def game(p0, p1):
    return fixedLengthTournament(p0, p1, 16, standardScore)

m = 1.01
tft.handicap = m
stft.handicap = m
pavlov.handicap = m
spavlov.handicap = m
players = [allc, tft, spavlov, alld]
pops = [1.0, 1.0, 1.0, 1.0]
evo = ContinuousPopulationEvolution(players, pops, game)
result = "result = " + dict2Struct(evo.simulate(10000)) + ";"
result += "plot(1:result.length, result.pops);"
result += "legend("
for p in players:
    result += "'" + p.name + "',"

result = result[:-1] + ");"

f = open("cs6850pde.m", "w")
f.write(result)
f.close()

print("Finished.")